import React, { useEffect } from 'react';
import TextChatDialog from '../../../components/textChatDialog/TextChatDialog';
import useSpecialState from "../models/specialState";
import config from "../../../config/config";

const SpecialPage = (props) => {

    const {
        loading, setLoading,
        textChatMessages, setTextChatMessages,
        documentList, setDocumentList,
        selectedDocument, setSelectedDocument,
        focusBlurFlag, setFocusBlurFlag,
        completeStatus, setCompleteStatus,
        selectedPattern, setSelectedPattern,
        onSendChat, loadDocumentList
    } = useSpecialState();

    useEffect(() => {
        loadDocumentList({ current_page: "0", page_size: 10 });
    }, []);

    const documentOptions = documentList.map(item => {
        let optionObj = new Object();
        optionObj.label = item.document_name;
        optionObj.value = item.library_number;
        optionObj.desc = item.document_name;
        return optionObj;
    });

    const patternOptions = config.rag_specials.map(item => {
        let optionObj = new Object();
        optionObj.label = item.key + "（" + item.name + "）";
        optionObj.value = item.key;
        optionObj.disabled = item.disabled;
        return optionObj;
    });

    const textChatDialogProps = {
        loading,
        libraryVisible: false,
        pageSource: "special",
        textChatMessages,
        setTextChatMessages,
        selectedPattern,
        focusBlurFlag,
        completeStatus,
        patternOptions,
        documentOptions,
        selectDocument: setSelectedDocument,
        selectPattern: setSelectedPattern,
        focusBlurTextArea: setFocusBlurFlag,
        onSendChat: (values, query) => onSendChat(values, query)
    }

    return (
        <div style={{ width: "100%", height: "100%" }}>
            <TextChatDialog { ...textChatDialogProps } />
        </div>
    );
}

export default SpecialPage;
